package com.jy.task.fileoper;

import java.io.IOException;

import jcifs.smb.SmbFile;

public class SmbOper {

	String ip = "";
	String userName = "";
	String psw = "";
	String fileName = "";

	public SmbOper(String ip, String userName, String psw, String fileName) {

		this.ip = ip;
		this.userName = userName;
		this.fileName = fileName;
		this.psw = psw;
	}

	/**
	 * 判斷 ftp 是否能连接
	 * 
	 * @return
	 */
	public boolean tcpConnect() {
		boolean result = false;
		try {
			String pathString = "smb://" + this.userName + ":" + this.psw + "@"
					+ this.ip + this.fileName;
			if (!pathString.substring(pathString.length() - 1).equals("/")) {
				pathString += "/";
			}
			// System.out.println(">>>" + pathString);
			SmbFile remoteFile = new SmbFile(pathString);
			/*
			 * remoteFile.setReadTimeout(7200 * 1000);
			 * jcifs.Config.setProperty("jcifs.smb.client.responseTimeout",
			 * "7200000");
			 * jcifs.Config.setProperty("jcifs.smb.client.soTimeout",
			 * "7200000");
			 */
			remoteFile.connect();
			if (remoteFile.exists()) {
				result = true;
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

}
